<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>小程序邮件管理</title>
        <link rel="stylesheet" href="css/layui.css" media="all">
        <link rel="stylesheet" href="css/doc.css" media="all">
        <link href="css/bootstrap.min.css" rel="stylesheet">
    </head>

    <body>
        <div class="kit-doc">
            <blockquote class="layui-elem-quote">小程序邮件管理</blockquote>
            <table class="layui-table">
                <colgroup>
                    <col width="5">
                    <col width="5">
                    <col width="5">
                    <col width="5">
                </colgroup>
                <thead>
                <tr>
                    <th style="width: 35px">
                        <div class="layui-input-inline">
                            <input type="text" lay-verify="required" placeholder="请输入用户名称"
                                   autocomplete="off"
                                   class="layui-input queryName" value="${queryName}">
                        </div>
                    </th>
                    <th style="width: 35px">
                        <div class="layui-input-inline">
                            <input type="text" lay-verify="required" placeholder="请输入手机号"
                                   autocomplete="off"
                                   class="layui-input queryPhone" value="${queryPhone}">
                        </div>
                    </th>
                    <th style="width: 35px">
                        <div style="width: 150px">
                            <input type="date" class="form-control queryDate" id="recipient-pass" value="${queryDate}"/>
                        </div>
                    </th>
                    <th>
                        <div class="layui-btn-container">
                            <button type="button" class="layui-btn layui-btn-normal query">查询</button>
                        </div>
                    </th>
                </tr>
                </thead>
            </table>
            <table class="layui-table">
                <colgroup>
                    <col width="5">
                    <col width="70">
                    <col width="70">
                    <col width="200">
                    <col width="70">
                    <col width="70">
                </colgroup>
                <thead>
                <tr>
                    <th>id</th>
                    <th>用户姓名</th>
                    <th>电话</th>
                    <th>邮件内容</th>
                    <th>时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <#list emails.records as email>
                    <tr>
                        <td>${email.id}</td>
                        <td>${email.name}</td>
                        <td>${email.phone}</td>
                        <td>${email.content}</td>
                        <td>${(email.time?string("yyyy-MM-dd HH:mm:ss"))}</td>
                        <td>
                            <button class="btn btn-danger deleteEmailById">删除</button>
                        </td>
                    </tr>
                </#list>
                </tbody>
            </table>
        </div>
        <div id="demo" style="margin-left: 470px;"></div>
        <script src="js/jquery-3.5.1.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <script src="js/layui.all.js"></script>
        <script>
            //获取项目路径
            function URL() {
                return window.location.protocol + "//" + window.location.host + "/";
            }

            layui.use(['laypage', 'laydate'], function () {
                var laypage = layui.laypage
                    , laydate = layui.laydate;

                //日期
                laydate.render({
                    elem: '#date1'
                });

                laypage.render({
                    elem: 'demo'
                    , curr: ${emails.current}   //当前页数
                    , count: ${emails.total}    //总记录数
                    , limit: ${emails.size}      //每页记录数
                    , theme: '#009688'
                    , jump: function (obj, first) {
                        if (!first) {
                            var queryPhone = $(".queryPhone").val();
                            var queryName = $(".queryName").val();
                            var queryDate = $(".queryDate").val();
                            window.location.href = URL() + "appEmailManage?pageNum=" + obj.curr+"&queryPhone=" + queryPhone + "&queryName=" + queryName+ "&queryDate=" + queryDate;;
                        }
                    }
                });
            });


            $(".query").click(function () {
                var queryPhone = $(".queryPhone").val();
                var queryName = $(".queryName").val();
                var queryDate = $(".queryDate").val();
                window.location.href = URL() + "appEmailManage?pageNum=1&queryPhone=" + queryPhone + "&queryName=" + queryName+ "&queryDate=" + queryDate;
            })

            //删除邮件
            $('.deleteEmailById').click(function () {
                let id = $(this).parents("tr").find("td").eq(0).text();
                if (window.confirm("确认删除第 " + id + " 封邮件吗?")) {
                    //删除邮件
                    $.ajax({
                        url: URL() + "delEmail?",
                        type: "DELETE",
                        data: "id=" + id,
                        success: function () {
                            window.location.reload();
                        }
                    });
                }


            });
        </script>
    </body>
</html>